/*
 * Copyright (c) 2023.11.29 Fengxun
 * Version:5.2.2
 */

// type=105 填空题
const {
  getCheckpointList,
  saveCheckpointList,
  getCheckpointByID
} = require("../../utils/initdata")

const {
  getPageConfig,
  saveRemoteRecord,
  saveRemoteGold
} = require("../../utils/custom_loading")

const {
  DefaultItemType,
  RightItemType,
  RedoItemType,
  getNextFlowItemByType,
  doEndTask,
} = require("../../utils/task")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    input_answer: ''
  },

  onInputChange(e) {
    this.setData({
      input_answer: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 页面UI配置
    const config = getPageConfig('task')
    if (config) {
      this.setData({
        config: config
      })
    }

    // 页面显示数据
    this.checkpoint_list = getCheckpointList()
    this.checkpoint = getCheckpointByID(this.checkpoint_list, options.id)
    this.task = this.checkpoint.workflow.flow[this.checkpoint.workflow.step]
    const content = this.task.content.trim()
    this.setData({
      isWelcome: wx.getStorageSync('welcome'),
      checkpoint: this.checkpoint,
      content: content == '' ? [] : content.split('\n'),
      task: this.task
    })
  },

  onEndTask() {
    doEndTask(this.checkpoint_list, this.checkpoint, this.data.task, this.data.input_answer)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})